package com.leo.base_project.entity;

import com.leo.base_project.Utils.UIUtils;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/*
 * 类名：OnlineData
 * 功能：用于保存用户和设备等消息的上下线信息，便于后续分析处理
 * todo 等socket做完了再做吧
 * 创建时间: 2021/8/27 10:00
 * 创建者：Leo
 */
@Entity
public class OnlineData {
    @Id
    Long id;

    String type;
    String name;
    Date OnlineTime;
    Date OfflineTime;

    @Generated(hash = 125098605)
    public OnlineData(Long id, String type, String name, Date OnlineTime, Date OfflineTime) {
        this.id = id;
        this.type = type;
        this.name = name;
        this.OnlineTime = OnlineTime;
        this.OfflineTime = OfflineTime;
    }

    @Generated(hash = 769588828)
    public OnlineData() {
    }

    public String getDuringOnlineTime(){
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss", Locale.CHINA);//初始化Formatter的转换格式。
        return formatter.format(OfflineTime.getTime() - OnlineTime.getTime());
    }

    @NotNull
    @Override
    public String toString() {
        return "id=" + id +
                ", 类型='" + type  +
                ", 名称='" + name  +
                ", 上线时间=" + UIUtils.formatDate(OnlineTime) +
                ", 下线时间=" + UIUtils.formatDate(OfflineTime) +
                ", 持续时间=" + getDuringOnlineTime();
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getOnlineTime() {
        return this.OnlineTime;
    }

    public void setOnlineTime(Date OnlineTime) {
        this.OnlineTime = OnlineTime;
    }

    public Date getOfflineTime() {
        return this.OfflineTime;
    }

    public void setOfflineTime(Date OfflineTime) {
        this.OfflineTime = OfflineTime;
    }
}
